home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / boot / diskBoot.OpenProm / sun4c.md / devSunProm.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-14  |  3.3 KB  |  140 lines

  1. /* 
  2.  * devSunProm.c --
  3.  *
  4.  *    Routines that access the Sun PROM device drivers.
  5.  *
  6.  * Copyright 1989 Regents of the University of California
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appear in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  */
  15.  
  16. #ifndef lint
  17. static char rcsid[] = "$Header: /sprite/src/boot/sunprom/RCS/devSunProm.c,v 1.2 90/09/17 11:05:25 jhh Exp Locker: rab $ SPRITE (Berkeley)";
  18. #endif /* not lint */
  19.  
  20.  
  21. #include "sprite.h"
  22. #include "stdlib.h"
  23. #include "user/fs.h"
  24. #include "dev.h"
  25. #include "devFsOpTable.h"
  26. #include "machMon.h"
  27. #include "boot.h"
  28. #include "fs.h"
  29.  
  30. static void *fileId;
  31.  
  32.  
  33. /*
  34.  *----------------------------------------------------------------------
  35.  *
  36.  * SunPromDevOpen --
  37.  *
  38.  *    Open the device used for booting.  This depends on the initialization
  39.  *    of the devicePtr->data field done in Dev_Config.
  40.  *
  41.  * Results:
  42.  *    SUCCESS or FAILURE.
  43.  *
  44.  * Side effects:
  45.  *    None.
  46.  *
  47.  *----------------------------------------------------------------------
  48.  */
  49. ReturnStatus
  50. SunPromDevOpen(devicePtr)
  51.     Fs_Device    *devicePtr;    /* Sprite device description */
  52. {
  53.     char *bootDevName = (char *)devicePtr->data;
  54.  
  55.     if (romVectorPtr->v_romvec_version >= 2) {
  56.     fileId = (void *)(*romVectorPtr->op_open)(bootDevName);
  57.     } else {
  58.     fileId = (void *)(*romVectorPtr->v_open)(bootDevName);
  59.     }
  60.     if (fileId != 0) {
  61.     return(SUCCESS);
  62.     } else {
  63.     Mach_MonPrintf("v_open(\"%s\") failed\n", bootDevName);
  64.     return(FAILURE);
  65.     }
  66. }
  67.  
  68.  
  69. /*
  70.  *----------------------------------------------------------------------
  71.  *
  72.  * SunPromDevClose --
  73.  *
  74.  *    Close the device used for booting.
  75.  *
  76.  * Results:
  77.  *    void
  78.  *
  79.  * Side effects:
  80.  *    None.
  81.  *
  82.  *----------------------------------------------------------------------
  83.  */
  84. void
  85. SunPromDevClose()
  86. {
  87.     if (romVectorPtr->v_romvec_version >= 2) {
  88.     (void)(*romVectorPtr->op_close)(fileId);
  89.     } else {
  90.     (void)(*romVectorPtr->v_close)(fileId);
  91.     }
  92.     return;
  93. }
  94.  
  95.  
  96. /*
  97.  *----------------------------------------------------------------------
  98.  *
  99.  * SunPromDevRead --
  100.  *
  101.  *    Read from the boot device used for booting.
  102.  *
  103.  * Results:
  104.  *    SUCCESS or FAILURE.
  105.  *
  106.  * Side effects:
  107.  *    The read operation.
  108.  *
  109.  *----------------------------------------------------------------------
  110.  */
  111. ReturnStatus
  112. SunPromDevRead(devicePtr, ioPtr, replyPtr)
  113.     Fs_Device    *devicePtr;    /* Sprite device description */
  114.     Fs_IOParam  *ioPtr;
  115.     Fs_IOReply  *replyPtr;
  116. {
  117.     int numBytes, blockNumber, numBlocks, blocksRead;
  118.  
  119.     blockNumber = ioPtr->offset / DEV_BYTES_PER_SECTOR;
  120.     numBlocks = ioPtr->length / DEV_BYTES_PER_SECTOR;
  121.  
  122.     if (romVectorPtr->v_romvec_version >= 2) {
  123.     (*romVectorPtr->op_seek)(fileId,
  124.         0, blockNumber * DEV_BYTES_PER_SECTOR);
  125.     replyPtr->length = (*romVectorPtr->op_read)(fileId,
  126.         ioPtr->buffer, numBlocks * DEV_BYTES_PER_SECTOR);
  127.     } else {
  128.     blocksRead = (*romVectorPtr->v_read_blocks)(fileId,
  129.         numBlocks, blockNumber, ioPtr->buffer);
  130.  
  131.     replyPtr->length = blocksRead * DEV_BYTES_PER_SECTOR;
  132.     }
  133.  
  134.     if (numBlocks < 0) {
  135.     return(FAILURE);
  136.     } else {
  137.     return(SUCCESS);
  138.     }
  139. }
  140.